<!--
 * @Author: gaoyu gy15354315043@163.com
 * @Date: 2024-10-15 17:09:57
 * @LastEditors: 郝奔 1425466221@qq.com
 * @LastEditTime: 2024-11-25 10:55:27
 * @Description: 消息详情
 * Copyright (c) 2024-present HBIS Digital Technology Co.,Ltd. All rights reserved. 
-->
<template>
    <div class="topbox">
        <el-page-header @back="goBack">
            <template #content>
                <span>{{ messageData.messageCategory == 1 ? '平台消息' : '通知公告' }}</span>
            </template>
        </el-page-header>
        <!-- <el-button @click="goBack" link :icon="Back"></el-button>
        <span>{{messageData.messageCategory==1?'平台消息':'通知公告'}}</span> -->
    </div>
    <div class="dt-table-container card table-main table-fullscreen messageDetail">
        <div class="messageHeader">
            <div class="messageTitle">
                {{ messageData.messageTitle }}
            </div>
            <div class="messageDesc" :class="{ platMessage: messageData.messageCategory == 2 }">
                <div class="level" v-if="messageData.messageCategory == 1">优先级：{{ messageData.level }}</div>
                <div class="time">通知时间：{{ messageData.realSendTime }}</div>
            </div>
        </div>
        <div class="messageContent">
            {{ messageData.messageContent }}
        </div>
    </div>
</template>
<script lang="ts" setup>
import { useRoute, useRouter } from 'vue-router';
import { read, unReadMessage } from '../../api/index'
import { platMessageListType } from '../../api/types'
import { getDictData } from '@/framework/modules/basic-services/api/system-config/dict-management/dict-enum-manage/index'
import { useWebsocketStore } from '@/framework/store/modules/websocket';
const websocketStore = useWebsocketStore()
const router = useRouter()
const route = useRoute()
interface messageType extends platMessageListType {
    level: string | number,
}
const messageData = ref<Partial<messageType>>({
    messageTitle: '',
    level: '',
    realSendTime: '',
    messageContent: '',
    messageCategory: 2
})
onMounted(() => [
    initData()
])
/**
 * @description: 初始化数据
 * @return {*}
 */
async function initData(): Promise<void> {
    const queryString = window.location.search;
    const params = new URLSearchParams(queryString);
    const messageId = params.get('messageId') || '';
    const queryMessageId = messageId ? messageId : route.query.messageId
    const res = await read({ messageId: queryMessageId })
    messageData.value = res.data
    if (res.data.messageCategory == 1) {
        const dictData = await getDictData({ dictCode: 'messagePriorityLevel' })
        messageData.value.level = dictData.data.filter(item => item.dictEnumCode == messageData.value.priorityLevel)[0].dictEnumName
    }
    await initUnReadMessage()
}
/**
 * @description:  查看全部
 * @return {*}
 */
function goBack(): void {
    if (messageData.value.messageCategory == 1) {
        openMessage('/messageCenter/platformMessage')
        // router.push('/messageCenter/platformMessage')
    } else {
        openMessage('/messageCenter/noticeList')
        // router.push('/messageCenter/noticeList')
    }
}
/**
 * @description: 跳转方法
 * @param {*} path
 * @return {*}
 */
function openMessage(path: string): void {
    router.replace(path)
    // window.open(router.resolve(path).href, '_blank')
}
/**
 * @description: 刷新小铃铛未读消息
 * @return {*}
 */
async function initUnReadMessage(): Promise<void> {
    const res = await unReadMessage()
    websocketStore.setIsUnReadMessage(res.data)
}
defineExpose({
    initData
})
</script>
<style scoped lang="scss">
.topbox {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 40px;
    line-height: 40px;
    background-color: #fff;
    display: flex;
    align-items: center;
    padding: 0 16px;
    font-size: 18px;
    color: #131414;

    :deep(.el-page-header__content) {
        color: #131414;
    }
}

.messageDetail {
    box-sizing: border-box;
    margin-top: 40px;
    padding: 40px;

    .messageHeader {
        height: 62px;
        border-bottom: 1px solid #D8D8D8;

        .messageTitle {
            font-size: 18px;
            height: 26px;
            line-height: 26px;
            font-weight: 500;
            color: #131414;
            text-align: center;
            margin-bottom: 8px;
        }

        .messageDesc {
            display: flex;
            justify-content: space-between;
            font-size: 12px;
            line-height: 20px;
            color: #606266;
            margin-bottom: 8px;
        }

        .platMessage {
            display: flex;
            justify-content: flex-end;
        }
    }

    .messageContent {
        margin-top: 24px;
        font-size: 14px;
        color: #131414;
        line-height: 22px;
    }
}
</style>